import request from "@/utils/request";
import type {SysRoleQuery, SysRoleType} from "@/types/system";

const baseUrl = '/system/role';

export function getPageList(query: SysRoleQuery, current = 1, size = 20) {
    return request({
        url: `${baseUrl}/search`,
        method: 'POST',
        data: { ...query, current, size},
    })
}

export function deleteById(id: string) {
    return request({
        url: `${baseUrl}/${id}`,
        method: 'DELETE',
    });
}

export function add(data: SysRoleType) {
    return request({
        url: `${baseUrl}`,
        method: 'POST',
        data,
    });
}

export function update(data: SysRoleType) {
    return request({
        url: `${baseUrl}`,
        method: 'PUT',
        data,
    });
}

export function getMenuIdsByRoleId(roleId: string) {
    return request({
        url: `/menu/role/${roleId}/ids`,
        method: 'GET',
    });
}

export function saveRoleMenu(roleId: string, menuIds: string[]) {
    return request({
        url: `/menu/role/${roleId}/ids`,
        method: 'POST',
        data:menuIds,
    });
}

export function getRoleList() {
    return request({
        url: `${baseUrl}/list`,
        method: 'GET',
    });
}

export function getRoleListSelect() {
    return request({
        url: `${baseUrl}/optionselect`,
        method: 'GET',
    });
}
